//
// Created by ascend on 2020/9/3.
//

#ifndef AIPAINTING_ATLAS200DK_V2_DATA_RECEIVER_H
#define AIPAINTING_ATLAS200DK_V2_DATA_RECEIVER_H


#include <iostream>
#include <string>
#include <dirent.h>
#include <memory>
#include <unistd.h>
#include <vector>
#include <stdint.h>

#include "presenter_channels.h"
#include "utils.h"

#define INPUT_SIZE 1
#define OUTPUT_SIZE 1

const int32_t kMaxFaceIdLength = 50;

// sleep interval when queue full (unit:microseconds)
const __useconds_t kSleepInterval = 200000;

// function of dvpp returns success
const int kDvppOperationOk = 0;

// IP regular expression
const std::string kIpRegularExpression =
        "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\."
        "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
        "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\."
        "(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";

// port number range
const int32_t kPortMinNumber = 1024;
const int32_t kPortMaxNumber = 49151;

// app name regular expression
const std::string kAppNameRegularExpression = "[a-zA-Z0-9_]{3,20}";

// presenter server ip
const std::string kPresenterServerIP = "presenter_server_ip";

// presenter server port
const std::string kPresenterServerPort = "presenter_server_port";

// app name
const std::string kAppName = "app_name";

// app type
const std::string kAppType = "display";

class  DataReceiver {
public:
    /**
     * @brief   constructor
     */
     DataReceiver()
//            : input_que_(INPUT_SIZE)
    {
    }

    /**
     * @brief   destructor
     */
    ~ DataReceiver() = default;

    /**
     * @brief  init config of face register by aiConfig
     * @param [in] config:  initialized aiConfig
     * @param [in] model_desc:  modelDesc
     * @return  success --> HIAI_OK ; fail --> HIAI_ERROR
     */
//    HIAI_StatusT Init(const hiai::AIConfig& config,
//                      const std::vector<hiai::AIModelDescription>& model_desc);
    Result Init();

    /**
     * @brief: validate IP address
     * @param [in]: IP address
     * @return: true: invalid
     *          false: valid
     */
    bool IsInvalidIp(const std::string &ip);

    /**
     * @brief: validate port
     * @param [in]: port
     * @return: true: invalid
     *          false: valid
     */
    bool IsInvalidPort(const std::string &port);

    /**
     * @brief: validate app name
     * @param [in]: app name
     * @return: true: invalid
     *          false: valid
     */
    bool IsInvalidAppName(const std::string &app_name);

    /**
     * @brief  handle registered image and send to next engine
     * @return  success --> true ; fail --> false
     */
    bool DoReceiverProcess(void* objectDta, void* layoutData);

    /**
     * @brief  reload Engine Process
     * @param [in]  define the number of input and output
     */
//    HIAI_DEFINE_PROCESS(INPUT_SIZE, OUTPUT_SIZE)

private:
    // Private implementation a member variable,
    // which is used to cache the input queue
//    hiai::MultiTypeQueue input_que_;

};

#endif //AIPAINTING_ATLAS200DK_V2_DATA_RECEIVER_H
